
#!/bin/bash


### init config
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
source /etc/profile

#各种路径，（项目路径，tomcat部署路径，tomcat路径）
#!/bin/bash
PRE_DIR=`dirname $0`
PROJECT_DIR=/data/web/hf_app/build.club
PROJECT_NAME=tiger
PROJECT_CLUB=tiger/tiger-club/tiger-club-provider
DOC_ROOT=$PROJECT_DIR/ROOT
WAR_FILE=$PROJECT_DIR/$PROJECT_CLUB/target/tiger-club.war
#TOMCAT=/usr/local/app/club-tomcat
DATE=`date "+%Y%m%d%H%M%S"`
STR_DATE=`date "+%s"`
backup="backup"

#backup
tar -zcvf ROOT."$DATE".tar.gz $PROJECT_DIR/ROOT
mv ROOT.$DATE.tar.gz $backup/
#deploy
echo
echo Deploy:
echo


#从从git上更新

cd $PROJECT_DIR/$PROJECT_NAME
git clean -d -fx
git checkout master
git pull
if [ ! -z $1 ]
then
    git branch -D test
    git fetch xxx.com/xxx refs/changes/$1 && git checkout FETCH_HEAD
    git checkout -b test
else
    git  checkout qa
    git pull
    git branch -D test
    git checkout -b test
fi

#maven打包并复制到tomcat的部署路径
mvn clean package -DskipTests -U 
rm -rf $PROJECT_DIR/ROOT
mkdir -p  $PROJECT_DIR/ROOT
unzip -q $WAR_FILE -d $PROJECT_DIR/ROOT
cp $PROJECT_DIR/config-toolkit.properties $DOC_ROOT/WEB-INF/classes/properties
#find $PROJECT_DIR/ROOT -name "*.vm" |xargs sed -i 's/szone/'$STR_DATE'/g'


#restart tomcat
#echo
#echo Restart tomcat:
#ps aux |grep -v grep |grep $TOMCAT|awk '{print $2}'|xargs kill -9
#rm -rf $TOMCAT/work/Catalina
# sleep 10s
#echo "Waiting shutdown Tomcat, Sleep 10s..."
#sleep 10s
#echo "Start to startup Tomcat..."
#$TOMCAT/bin/startup.sh

